/*!
 * jQuery Upload File Plugin
 * version: 2.0.4
 * @requires jQuery v1.5 or later & form plugin
 * Copyright (c) 2013 Ravishanker Kusuma
 * http://hayageek.com/
 */
(function (b) {
    var a = {};
    a.fileapi = b("<input type='file'/>").get(0).files !== undefined;
    a.formdata = window.FormData !== undefined;
    b.fn.uploadFile = function (m) {
        var l = b.extend({
            url: "",
            method: "POST",
            enctype: "multipart/form-data",
            formData: null,
            returnType: null,
            allowedTypes: "*",
            fileName: "file",
            multiple: true,
            dragDrop: true,
            autoSubmit: true,
            showCancel: true,
            showAbort: true,
            showDone: true,
            showStatusAfterSuccess: true,
            showStatusAfterError: true,
            buttonCss: false,
            buttonClass: false,
            onSubmit: function (n) { },
            onSuccess: function (o, n, p) { },
            onError: function (p, n, o) { },
            uploadButtonClass: "ajax-file-upload",
            dragDropStr: "<span><b>Drag &amp; Drop Files</b></span>"
        },
        m);
        this.fileCounter = 1;
        if (!a.formdata) {
            l.dragDrop = false
        }
        var d = "ajax-file-upload-" + (new Date().getTime());
        var e = b('<label for="" >' + b(this).html() + "</label>");
        b(e).addClass(l.uploadButtonClass);
        if (l.dragDrop) {
            var g = b('<div class="ajax-upload-dragdrop"></div>');
            b(this).before(g);
            b(g).append(e);
            b(g).append(b(l.dragDropStr));
            f(this, l, g)
        } else {
            b(this).before(e)
        }
        this.formGroup = d;
        k(this, d, l, e);
        this.startUpload = function () {
            b("." + this.formGroup).each(function (o, n) {
                b(this).submit()
            })
        };
        b(this).hide();
        function f(p, n, o) {
            o.on("dragenter",
            function (q) {
                q.stopPropagation();
                q.preventDefault();
                b(this).css("border", "2px solid #A5A5C7")
            });
            o.on("dragover",
            function (q) {
                q.stopPropagation();
                q.preventDefault()
            });
            o.on("dragexit",
            function (q) {
                q.stopPropagation();
                q.preventDefault()
            });
            o.on("drop",
            function (r) {
                b(this).css("border", "2px dotted #A5A5C7");
                r.preventDefault();
                var q = r.originalEvent.dataTransfer.files;
                h(n, p, q)
            });
            b(document).on("dragenter",
            function (q) {
                q.stopPropagation();
                q.preventDefault()
            });
            b(document).on("dragover",
            function (q) {
                q.stopPropagation();
                q.preventDefault()
            });
            b(document).on("dragexit",
            function (q) {
                q.stopPropagation();
                q.preventDefault()
            });
            b(document).on("drop",
            function (q) {
                q.preventDefault()
            })
        }
        function i(r) {
            var s = [];
            if (jQuery.type(r) == "string") {
                s = r.split("&")
            } else {
                s = b.param(r).split("&")
            }
            var o = s.length;
            var n = [];
            var q, p;
            for (q = 0; q < o; q++) {
                s[q] = s[q].replace(/\+/g, " ");
                p = s[q].split("=");
                n.push([decodeURIComponent(p[0]), decodeURIComponent(p[1])])
            }
            return n
        }
        function h(y, t, n) {
            for (var u = 0; u < n.length; u++) {
                if (c(t, y, n[u].name)) {
                    var v = y;
                    var p = new FormData();
                    p.append(y.fileName, n[u]);
                    if (y.formData) {
                        var x = i(y.formData);
                        for (var r = 0; r < x.length; r++) {
                            if (x[u]) {
                                p.append(x[r][0], x[r][1])
                            }
                        }
                    }
                    v.fileData = p;
                    var w = new j(t);
                    w.filename.html(t.fileCounter + "). " + n[u].name);
                    var o = b("<form style='display:block; position:absolute;left: 150px;' class='" + t.formGroup + "' method='" + y.method + "' action='" + y.url + "' enctype='" + y.enctype + "'></form>");
                    o.appendTo("body");
                    var q = [];
                    q.push(n[u].name);
                    b.fn.uploadFile.ajaxFormSubmit(o, v, w, q);
                    t.fileCounter++
                }
            }
        }
        function c(p, o, r) {
            var q = o.allowedTypes.toLowerCase().split(",");
            var n = r.split(".").pop().toLowerCase();
            if (o.allowedTypes != "*" && jQuery.inArray(n, q) < 0) {
                return false
            }
            return true
        }
        function k(u, t, p, n) {
            var v = "ajax-upload-id-" + (new Date().getTime());
            var r = b("<form method='" + p.method + "' action='" + p.url + "' enctype='" + p.enctype + "'></form>");
            var o = "<input type='file' id='" + v + "' name='" + p.fileName + "'/>";
            if (p.multiple) {
                if (p.fileName.indexOf("[]") != p.fileName.length - 2) {
                    p.fileName += "[]"
                }
                o = "<input type='file' id='" + v + "' name='" + p.fileName + "' multiple/>"
            }
            var q = b(o).appendTo(r);
            q.change(function () {
                var B = p.allowedTypes.toLowerCase().split(",");
                var x = [];
                if (this.files) {
                    for (y = 0; y < this.files.length; y++) {
                        if (!c(u, p, this.files[y].name)) {
                            alert("File type is not allowed. Allowed only: " + p.allowedTypes);
                            return
                        }
                        x.push(this.files[y].name)
                    }
                } else {
                    var z = b(this).val();
                    x.push(z);
                    if (!c(u, p, z)) {
                        alert("File type is not allowed. Allowed only: " + p.allowedTypes);
                        return
                    }
                }
                n.unbind("click");
                k(u, t, p, n);
                r.addClass(t);
                if (p.multiple && a.formdata) {
                    r.removeClass(t);
                    var A = this.files;
                    h(p, u, A)
                } else {
                    var w = "";
                    for (var y = 0; y < x.length; y++) {
                        w += u.fileCounter + "). " + x[y] + "<br>";
                        u.fileCounter++
                    }
                    var s = new j(u);
                    s.filename.html(w);
                    b.fn.uploadFile.ajaxFormSubmit(r, p, s, x)
                }
            });
            r.css({
                margin: 0,
                padding: 0,
                display: "block",
                position: "absolute",
                left: "-550px"
            });
            r.appendTo("body");
            if (navigator.appVersion.indexOf("MSIE ") != -1) {
                n.attr("for", v)
            } else {
                n.click(function () {
                    q.click()
                })
            }
        }
        function j(n) {
            this.statusbar = b("<div class='ajax-file-upload-statusbar'></div>");
            this.filename = b("<div class='ajax-file-upload-filename'></div>").appendTo(this.statusbar);
            this.progressDiv = b("<div class='ajax-file-upload-progress'>").appendTo(this.statusbar).hide();
            this.progressbar = b("<div class='ajax-file-upload-bar'></div>").appendTo(this.progressDiv);
            this.abort = b("<div class='ajax-file-upload-red'>Abort</div>").appendTo(this.statusbar).hide();
            this.cancel = b("<div class='ajax-file-upload-red'>Cancel</div>").appendTo(this.statusbar).hide();
            this.done = b("<div class='ajax-file-upload-green'>Done</div>").appendTo(this.statusbar).hide();
            n.after(this.statusbar);
            return this
        }
        return this
    };
    b.fn.uploadFile.ajaxFormSubmit = function (h, g, c, e) {
        var f = null;
        var d = {
            cache: false,
            contentType: false,
            processData: false,
            forceSync: false,
            data: g.formData,
            fileData: g.fileData,
            dataType: g.returnType,
            beforeSend: function (j, i) {
                g.onSubmit.call(this, e);
                c.progressDiv.show();
                c.cancel.hide();
                c.done.hide();
                if (g.showAbort) {
                    c.abort.show();
                    c.abort.click(function () {
                        j.abort()
                    })
                }
                if (!a.formdata) {
                    c.progressbar.width("5%")
                }
            },
            uploadProgress: function (m, i, l, k) {
                var j = k + "%";
                c.progressbar.width(j)
            },
            success: function (j, i, k) {
                c.abort.hide();
                g.onSuccess.call(this, e, j, k);
                if (g.showStatusAfterSuccess) {
                    if (g.showDone) {
                        c.done.show();
                        c.done.click(function () {
                            c.statusbar.hide("slow")
                        })
                    } else {
                        c.done.hide()
                    }
                    c.progressbar.width("100%")
                } else {
                    c.statusbar.hide("slow")
                }
                h.remove()
            },
            error: function (k, i, j) {
                c.abort.hide();
                if (k.statusText == "abort") {
                    c.statusbar.hide("slow")
                } else {
                    g.onError.call(this, e, i, j);
                    if (g.showStatusAfterError) {
                        c.progressDiv.hide();
                        c.statusbar.append("<font color='red'>ERROR: " + j + "</font>")
                    } else {
                        c.statusbar.hide()
                    }
                }
                h.remove()
            }
        };
        if (g.autoSubmit) {
            h.ajaxSubmit(d)
        } else {
            if (g.showCancel) {
                c.cancel.show();
                c.cancel.click(function () {
                    h.remove();
                    c.statusbar.remove()
                })
            }
            h.ajaxForm(d)
        }
    };
    if (b.fn.ajaxForm == undefined) {
        /*!
         * jQuery Form Plugin
         * version: 3.40.0-2013.08.13
         * @requires jQuery v1.5 or later
         * Copyright (c) 2013 M. Alsup
         * Examples and documentation at: http://malsup.com/jquery/form/
         * Project repository: https://github.com/malsup/form
         * Dual licensed under the MIT and GPL licenses.
         * https://github.com/malsup/form#copyright-and-license
         */
        ; (function (h) {
            var e = {};
            e.fileapi = h("<input type='file'/>").get(0).files !== undefined;
            e.formdata = window.FormData !== undefined;
            var g = !!h.fn.prop;
            h.fn.attr2 = function () {
                if (!g) {
                    return this.attr.apply(this, arguments)
                }
                var i = this.prop.apply(this, arguments);
                if ((i && i.jquery) || typeof i === "string") {
                    return i
                }
                return this.attr.apply(this, arguments)
            };
            h.fn.ajaxSubmit = function (m) {
                if (!this.length) {
                    f("ajaxSubmit: skipping submit process - no element selected");
                    return this
                }
                var l, E, o, r = this;
                if (typeof m == "function") {
                    m = {
                        success: m
                    }
                } else {
                    if (m === undefined) {
                        m = {}
                    }
                }
                l = m.type || this.attr2("method");
                E = m.url || this.attr2("action");
                o = (typeof E === "string") ? h.trim(E) : "";
                o = o || window.location.href || "";
                if (o) {
                    o = (o.match(/^([^#]+)/) || [])[1]
                }
                m = h.extend(true, {
                    url: o,
                    success: h.ajaxSettings.success,
                    type: l || h.ajaxSettings.type,
                    iframeSrc: /^https/i.test(window.location.href || "") ? "javascript:false" : "about:blank"
                },
                m);
                var w = {};
                this.trigger("form-pre-serialize", [this, m, w]);
                if (w.veto) {
                    f("ajaxSubmit: submit vetoed via form-pre-serialize trigger");
                    return this
                }
                if (m.beforeSerialize && m.beforeSerialize(this, m) === false) {
                    f("ajaxSubmit: submit aborted via beforeSerialize callback");
                    return this
                }
                var p = m.traditional;
                if (p === undefined) {
                    p = h.ajaxSettings.traditional
                }
                var u = [];
                var G, H = this.formToArray(m.semantic, u);
                if (m.data) {
                    m.extraData = m.data;
                    G = h.param(m.data, p)
                }
                if (m.beforeSubmit && m.beforeSubmit(H, this, m) === false) {
                    f("ajaxSubmit: submit aborted via beforeSubmit callback");
                    return this
                }
                this.trigger("form-submit-validate", [H, this, m, w]);
                if (w.veto) {
                    f("ajaxSubmit: submit vetoed via form-submit-validate trigger");
                    return this
                }
                var A = h.param(H, p);
                if (G) {
                    A = (A ? (A + "&" + G) : G)
                }
                if (m.type.toUpperCase() == "GET") {
                    m.url += (m.url.indexOf("?") >= 0 ? "&" : "?") + A;
                    m.data = null
                } else {
                    m.data = A
                }
                var J = [];
                if (m.resetForm) {
                    J.push(function () {
                        r.resetForm()
                    })
                }
                if (m.clearForm) {
                    J.push(function () {
                        r.clearForm(m.includeHidden)
                    })
                }
                if (!m.dataType && m.target) {
                    var n = m.success ||
                    function () { };
                    J.push(function (q) {
                        var k = m.replaceTarget ? "replaceWith" : "html";
                        h(m.target)[k](q).each(n, arguments)
                    })
                } else {
                    if (m.success) {
                        J.push(m.success)
                    }
                }
                m.success = function (M, q, N) {
                    var L = m.context || this;
                    for (var K = 0,
                    k = J.length; K < k; K++) {
                        J[K].apply(L, [M, q, N || r, r])
                    }
                };
                if (m.error) {
                    var B = m.error;
                    m.error = function (L, k, q) {
                        var K = m.context || this;
                        B.apply(K, [L, k, q, r])
                    }
                }
                if (m.complete) {
                    var j = m.complete;
                    m.complete = function (K, k) {
                        var q = m.context || this;
                        j.apply(q, [K, k, r])
                    }
                }
                var F = h('input[type=file]:enabled:not([value=""])', this);
                var s = F.length > 0;
                var D = "multipart/form-data";
                var z = (r.attr("enctype") == D || r.attr("encoding") == D);
                var y = e.fileapi && e.formdata;
                f("fileAPI :" + y);
                var t = (s || z) && !y;
                var x;
                if (m.iframe !== false && (m.iframe || t)) {
                    if (m.closeKeepAlive) {
                        h.get(m.closeKeepAlive,
                        function () {
                            x = I(H)
                        })
                    } else {
                        x = I(H)
                    }
                } else {
                    if ((s || z) && y) {
                        x = v(H)
                    } else {
                        x = h.ajax(m)
                    }
                }
                r.removeData("jqxhr").data("jqxhr", x);
                for (var C = 0; C < u.length; C++) {
                    u[C] = null
                }
                this.trigger("form-submit-notify", [this, m]);
                return this;
                function i(M) {
                    var N = h.param(M, m.traditional).split("&");
                    var q = N.length;
                    var k = [];
                    var L, K;
                    for (L = 0; L < q; L++) {
                        N[L] = N[L].replace(/\+/g, " ");
                        K = N[L].split("=");
                        k.push([decodeURIComponent(K[0]), decodeURIComponent(K[1])])
                    }
                    return k
                }
                function v(q) {
                    var k = new FormData();
                    for (var K = 0; K < q.length; K++) {
                        k.append(q[K].name, q[K].value)
                    }
                    if (m.extraData) {
                        var N = i(m.extraData);
                        for (K = 0; K < N.length; K++) {
                            if (N[K]) {
                                k.append(N[K][0], N[K][1])
                            }
                        }
                    }
                    m.data = null;
                    var M = h.extend(true, {},
                    h.ajaxSettings, m, {
                        contentType: false,
                        processData: false,
                        cache: false,
                        type: l || "POST"
                    });
                    if (m.uploadProgress) {
                        M.xhr = function () {
                            var O = h.ajaxSettings.xhr();
                            if (O.upload) {
                                O.upload.addEventListener("progress",
                                function (S) {
                                    var R = 0;
                                    var P = S.loaded || S.position;
                                    var Q = S.total;
                                    if (S.lengthComputable) {
                                        R = Math.ceil(P / Q * 100)
                                    }
                                    m.uploadProgress(S, P, Q, R)
                                },
                                false)
                            }
                            return O
                        }
                    }
                    M.data = null;
                    var L = M.beforeSend;
                    M.beforeSend = function (P, O) {
                        if (m.fileData) {
                            O.data = m.fileData
                        } else {
                            O.data = k
                        }
                        if (L) {
                            L.call(this, P, O)
                        }
                    };
                    return h.ajax(M)
                }
                function I(ah) {
                    var N = r[0],
                    M,
                    ad,
                    X,
                    af,
                    aa,
                    P,
                    S,
                    Q,
                    R,
                    ab,
                    ae,
                    V;
                    var ak = h.Deferred();
                    ak.abort = function (al) {
                        Q.abort(al)
                    };
                    if (ah) {
                        for (ad = 0; ad < u.length; ad++) {
                            M = h(u[ad]);
                            if (g) {
                                M.prop("disabled", false)
                            } else {
                                M.removeAttr("disabled")
                            }
                        }
                    }
                    X = h.extend(true, {},
                    h.ajaxSettings, m);
                    X.context = X.context || X;
                    aa = "jqFormIO" + (new Date().getTime());
                    if (X.iframeTarget) {
                        P = h(X.iframeTarget);
                        ab = P.attr2("name");
                        if (!ab) {
                            P.attr2("name", aa)
                        } else {
                            aa = ab
                        }
                    } else {
                        P = h('<iframe name="' + aa + '" src="' + X.iframeSrc + '" />');
                        P.css({
                            position: "absolute",
                            top: "-1000px",
                            left: "-1000px"
                        })
                    }
                    S = P[0];
                    Q = {
                        aborted: 0,
                        responseText: null,
                        responseXML: null,
                        status: 0,
                        statusText: "n/a",
                        getAllResponseHeaders: function () { },
                        getResponseHeader: function () { },
                        setRequestHeader: function () { },
                        abort: function (al) {
                            var am = (al === "timeout" ? "timeout" : "aborted");
                            f("aborting upload... " + am);
                            this.aborted = 1;
                            try {
                                if (S.contentWindow.document.execCommand) {
                                    S.contentWindow.document.execCommand("Stop")
                                }
                            } catch (an) { }
                            P.attr("src", X.iframeSrc);
                            Q.error = am;
                            if (X.error) {
                                X.error.call(X.context, Q, am, al)
                            }
                            if (af) {
                                h.event.trigger("ajaxError", [Q, X, am])
                            }
                            if (X.complete) {
                                X.complete.call(X.context, Q, am)
                            }
                        }
                    };
                    af = X.global;
                    if (af && 0 === h.active++) {
                        h.event.trigger("ajaxStart")
                    }
                    if (af) {
                        h.event.trigger("ajaxSend", [Q, X])
                    }
                    if (X.beforeSend && X.beforeSend.call(X.context, Q, X) === false) {
                        if (X.global) {
                            h.active--
                        }
                        ak.reject();
                        return ak
                    }
                    if (Q.aborted) {
                        ak.reject();
                        return ak
                    }
                    R = N.clk;
                    if (R) {
                        ab = R.name;
                        if (ab && !R.disabled) {
                            X.extraData = X.extraData || {};
                            X.extraData[ab] = R.value;
                            if (R.type == "image") {
                                X.extraData[ab + ".x"] = N.clk_x;
                                X.extraData[ab + ".y"] = N.clk_y
                            }
                        }
                    }
                    var W = 1;
                    var T = 2;
                    function U(an) {
                        var am = null;
                        try {
                            if (an.contentWindow) {
                                am = an.contentWindow.document
                            }
                        } catch (al) {
                            f("cannot get iframe.contentWindow document: " + al)
                        }
                        if (am) {
                            return am
                        }
                        try {
                            am = an.contentDocument ? an.contentDocument : an.document
                        } catch (al) {
                            f("cannot get iframe.contentDocument: " + al);
                            am = an.document
                        }
                        return am
                    }
                    var L = h("meta[name=csrf-token]").attr("content");
                    var K = h("meta[name=csrf-param]").attr("content");
                    if (K && L) {
                        X.extraData = X.extraData || {};
                        X.extraData[K] = L
                    }
                    function ac() {
                        var an = r.attr2("target"),
                        al = r.attr2("action");
                        N.setAttribute("target", aa);
                        if (!l) {
                            N.setAttribute("method", "POST")
                        }
                        if (al != X.url) {
                            N.setAttribute("action", X.url)
                        }
                        if (!X.skipEncodingOverride && (!l || /post/i.test(l))) {
                            r.attr({
                                encoding: "multipart/form-data",
                                enctype: "multipart/form-data"
                            })
                        }
                        if (X.timeout) {
                            V = setTimeout(function () {
                                ae = true;
                                Z(W)
                            },
                            X.timeout)
                        }
                        function ao() {
                            try {
                                var at = U(S).readyState;
                                f("state = " + at);
                                if (at && at.toLowerCase() == "uninitialized") {
                                    setTimeout(ao, 50)
                                }
                            } catch (au) {
                                f("Server abort: ", au, " (", au.name, ")");
                                Z(T);
                                if (V) {
                                    clearTimeout(V)
                                }
                                V = undefined
                            }
                        }
                        var am = [];
                        try {
                            if (X.extraData) {
                                for (var ar in X.extraData) {
                                    if (X.extraData.hasOwnProperty(ar)) {
                                        if (h.isPlainObject(X.extraData[ar]) && X.extraData[ar].hasOwnProperty("name") && X.extraData[ar].hasOwnProperty("value")) {
                                            am.push(h('<input type="hidden" name="' + X.extraData[ar].name + '">').val(X.extraData[ar].value).appendTo(N)[0])
                                        } else {
                                            am.push(h('<input type="hidden" name="' + ar + '">').val(X.extraData[ar]).appendTo(N)[0])
                                        }
                                    }
                                }
                            }
                            if (!X.iframeTarget) {
                                P.appendTo("body");
                                if (S.attachEvent) {
                                    S.attachEvent("onload", Z)
                                } else {
                                    S.addEventListener("load", Z, false)
                                }
                            }
                            setTimeout(ao, 15);
                            try {
                                N.submit()
                            } catch (ap) {
                                var aq = document.createElement("form").submit;
                                aq.apply(N)
                            }
                        } finally {
                            N.setAttribute("action", al);
                            if (an) {
                                N.setAttribute("target", an)
                            } else {
                                r.removeAttr("target")
                            }
                            h(am).remove()
                        }
                    }
                    if (X.forceSync) {
                        ac()
                    } else {
                        setTimeout(ac, 10)
                    }
                    var ai, aj, ag = 50,
                    O;
                    function Z(ar) {
                        if (Q.aborted || O) {
                            return
                        }
                        aj = U(S);
                        if (!aj) {
                            f("cannot access response document");
                            ar = T
                        }
                        if (ar === W && Q) {
                            Q.abort("timeout");
                            ak.reject(Q, "timeout");
                            return
                        } else {
                            if (ar == T && Q) {
                                Q.abort("server abort");
                                ak.reject(Q, "error", "server abort");
                                return
                            }
                        }
                        if (!aj || aj.location.href == X.iframeSrc) {
                            if (!ae) {
                                return
                            }
                        }
                        if (S.detachEvent) {
                            S.detachEvent("onload", Z)
                        } else {
                            S.removeEventListener("load", Z, false)
                        }
                        var ap = "success",
                        au;
                        try {
                            if (ae) {
                                throw "timeout"
                            }
                            var ao = X.dataType == "xml" || aj.XMLDocument || h.isXMLDoc(aj);
                            f("isXml=" + ao);
                            if (!ao && window.opera && (aj.body === null || !aj.body.innerHTML)) {
                                if (--ag) {
                                    f("requeing onLoad callback, DOM not available");
                                    setTimeout(Z, 250);
                                    return
                                }
                            }
                            var av = aj.body ? aj.body : aj.documentElement;
                            Q.responseText = av ? av.innerHTML : null;
                            Q.responseXML = aj.XMLDocument ? aj.XMLDocument : aj;
                            if (ao) {
                                X.dataType = "xml"
                            }
                            Q.getResponseHeader = function (ay) {
                                var ax = {
                                    "content-type": X.dataType
                                };
                                return ax[ay.toLowerCase()]
                            };
                            if (av) {
                                Q.status = Number(av.getAttribute("status")) || Q.status;
                                Q.statusText = av.getAttribute("statusText") || Q.statusText
                            }
                            var al = (X.dataType || "").toLowerCase();
                            var at = /(json|script|text)/.test(al);
                            if (at || X.textarea) {
                                var aq = aj.getElementsByTagName("textarea")[0];
                                if (aq) {
                                    Q.responseText = aq.value;
                                    Q.status = Number(aq.getAttribute("status")) || Q.status;
                                    Q.statusText = aq.getAttribute("statusText") || Q.statusText
                                } else {
                                    if (at) {
                                        var am = aj.getElementsByTagName("pre")[0];
                                        var aw = aj.getElementsByTagName("body")[0];
                                        if (am) {
                                            Q.responseText = am.textContent ? am.textContent : am.innerText
                                        } else {
                                            if (aw) {
                                                Q.responseText = aw.textContent ? aw.textContent : aw.innerText
                                            }
                                        }
                                    }
                                }
                            } else {
                                if (al == "xml" && !Q.responseXML && Q.responseText) {
                                    Q.responseXML = Y(Q.responseText)
                                }
                            }
                            try {
                                ai = k(Q, al, X)
                            } catch (an) {
                                ap = "parsererror";
                                Q.error = au = (an || ap)
                            }
                        } catch (an) {
                            f("error caught: ", an);
                            ap = "error";
                            Q.error = au = (an || ap)
                        }
                        if (Q.aborted) {
                            f("upload aborted");
                            ap = null
                        }
                        if (Q.status) {
                            ap = (Q.status >= 200 && Q.status < 300 || Q.status === 304) ? "success" : "error"
                        }
                        if (ap === "success") {
                            if (X.success) {
                                X.success.call(X.context, ai, "success", Q)
                            }
                            ak.resolve(Q.responseText, "success", Q);
                            if (af) {
                                h.event.trigger("ajaxSuccess", [Q, X])
                            }
                        } else {
                            if (ap) {
                                if (au === undefined) {
                                    au = Q.statusText
                                }
                                if (X.error) {
                                    X.error.call(X.context, Q, ap, au)
                                }
                                ak.reject(Q, "error", au);
                                if (af) {
                                    h.event.trigger("ajaxError", [Q, X, au])
                                }
                            }
                        }
                        if (af) {
                            h.event.trigger("ajaxComplete", [Q, X])
                        }
                        if (af && !--h.active) {
                            h.event.trigger("ajaxStop")
                        }
                        if (X.complete) {
                            X.complete.call(X.context, Q, ap)
                        }
                        O = true;
                        if (X.timeout) {
                            clearTimeout(V)
                        }
                        setTimeout(function () {
                            if (!X.iframeTarget) {
                                P.remove()
                            }
                            Q.responseXML = null
                        },
                        100)
                    }
                    var Y = h.parseXML ||
                    function (al, am) {
                        if (window.ActiveXObject) {
                            am = new ActiveXObject("Microsoft.XMLDOM");
                            am.async = "false";
                            am.loadXML(al)
                        } else {
                            am = (new DOMParser()).parseFromString(al, "text/xml")
                        }
                        return (am && am.documentElement && am.documentElement.nodeName != "parsererror") ? am : null
                    };
                    var q = h.parseJSON ||
                    function (al) {
                        return window["eval"]("(" + al + ")")
                    };
                    var k = function (aq, ao, an) {
                        var am = aq.getResponseHeader("content-type") || "",
                        al = ao === "xml" || !ao && am.indexOf("xml") >= 0,
                        ap = al ? aq.responseXML : aq.responseText;
                        if (al && ap.documentElement.nodeName === "parsererror") {
                            if (h.error) {
                                h.error("parsererror")
                            }
                        }
                        if (an && an.dataFilter) {
                            ap = an.dataFilter(ap, ao)
                        }
                        if (typeof ap === "string") {
                            if (ao === "json" || !ao && am.indexOf("json") >= 0) {
                                ap = q(ap)
                            } else {
                                if (ao === "script" || !ao && am.indexOf("javascript") >= 0) {
                                    h.globalEval(ap)
                                }
                            }
                        }
                        return ap
                    };
                    return ak
                }
            };
            h.fn.ajaxForm = function (i) {
                i = i || {};
                i.delegation = i.delegation && h.isFunction(h.fn.on);
                if (!i.delegation && this.length === 0) {
                    var j = {
                        s: this.selector,
                        c: this.context
                    };
                    if (!h.isReady && j.s) {
                        f("DOM not ready, queuing ajaxForm");
                        h(function () {
                            h(j.s, j.c).ajaxForm(i)
                        });
                        return this
                    }
                    f("terminating; zero elements found by selector" + (h.isReady ? "" : " (DOM not ready)"));
                    return this
                }
                if (i.delegation) {
                    h(document).off("submit.form-plugin", this.selector, d).off("click.form-plugin", this.selector, c).on("submit.form-plugin", this.selector, i, d).on("click.form-plugin", this.selector, i, c);
                    return this
                }
                return this.ajaxFormUnbind().bind("submit.form-plugin", i, d).bind("click.form-plugin", i, c)
            };
            function d(j) {
                var i = j.data;
                if (!j.isDefaultPrevented()) {
                    j.preventDefault();
                    h(this).ajaxSubmit(i)
                }
            }
            function c(m) {
                var l = m.target;
                var j = h(l);
                if (!(j.is("[type=submit],[type=image]"))) {
                    var i = j.closest("[type=submit]");
                    if (i.length === 0) {
                        return
                    }
                    l = i[0]
                }
                var k = this;
                k.clk = l;
                if (l.type == "image") {
                    if (m.offsetX !== undefined) {
                        k.clk_x = m.offsetX;
                        k.clk_y = m.offsetY
                    } else {
                        if (typeof h.fn.offset == "function") {
                            var n = j.offset();
                            k.clk_x = m.pageX - n.left;
                            k.clk_y = m.pageY - n.top
                        } else {
                            k.clk_x = m.pageX - l.offsetLeft;
                            k.clk_y = m.pageY - l.offsetTop
                        }
                    }
                }
                setTimeout(function () {
                    k.clk = k.clk_x = k.clk_y = null
                },
                100)
            }
            h.fn.ajaxFormUnbind = function () {
                return this.unbind("submit.form-plugin click.form-plugin")
            };
            h.fn.formToArray = function (z, k) {
                var y = [];
                if (this.length === 0) {
                    return y
                }
                var o = this[0];
                var r = z ? o.getElementsByTagName("*") : o.elements;
                if (!r) {
                    return y
                }
                var t, s, q, A, p, w, m;
                for (t = 0, w = r.length; t < w; t++) {
                    p = r[t];
                    q = p.name;
                    if (!q || p.disabled) {
                        continue
                    }
                    if (z && o.clk && p.type == "image") {
                        if (o.clk == p) {
                            y.push({
                                name: q,
                                value: h(p).val(),
                                type: p.type
                            });
                            y.push({
                                name: q + ".x",
                                value: o.clk_x
                            },
                            {
                                name: q + ".y",
                                value: o.clk_y
                            })
                        }
                        continue
                    }
                    A = h.fieldValue(p, true);
                    if (A && A.constructor == Array) {
                        if (k) {
                            k.push(p)
                        }
                        for (s = 0, m = A.length; s < m; s++) {
                            y.push({
                                name: q,
                                value: A[s]
                            })
                        }
                    } else {
                        if (e.fileapi && p.type == "file") {
                            if (k) {
                                k.push(p)
                            }
                            var l = p.files;
                            if (l.length) {
                                for (s = 0; s < l.length; s++) {
                                    y.push({
                                        name: q,
                                        value: l[s],
                                        type: p.type
                                    })
                                }
                            } else {
                                y.push({
                                    name: q,
                                    value: "",
                                    type: p.type
                                })
                            }
                        } else {
                            if (A !== null && typeof A != "undefined") {
                                if (k) {
                                    k.push(p)
                                }
                                y.push({
                                    name: q,
                                    value: A,
                                    type: p.type,
                                    required: p.required
                                })
                            }
                        }
                    }
                }
                if (!z && o.clk) {
                    var u = h(o.clk),
                    x = u[0];
                    q = x.name;
                    if (q && !x.disabled && x.type == "image") {
                        y.push({
                            name: q,
                            value: u.val()
                        });
                        y.push({
                            name: q + ".x",
                            value: o.clk_x
                        },
                        {
                            name: q + ".y",
                            value: o.clk_y
                        })
                    }
                }
                return y
            };
            h.fn.formSerialize = function (i) {
                return h.param(this.formToArray(i))
            };
            h.fn.fieldSerialize = function (j) {
                var i = [];
                this.each(function () {
                    var o = this.name;
                    if (!o) {
                        return
                    }
                    var l = h.fieldValue(this, j);
                    if (l && l.constructor == Array) {
                        for (var m = 0,
                        k = l.length; m < k; m++) {
                            i.push({
                                name: o,
                                value: l[m]
                            })
                        }
                    } else {
                        if (l !== null && typeof l != "undefined") {
                            i.push({
                                name: this.name,
                                value: l
                            })
                        }
                    }
                });
                return h.param(i)
            };
            h.fn.fieldValue = function (o) {
                for (var n = [], l = 0, j = this.length; l < j; l++) {
                    var m = this[l];
                    var k = h.fieldValue(m, o);
                    if (k === null || typeof k == "undefined" || (k.constructor == Array && !k.length)) {
                        continue
                    }
                    if (k.constructor == Array) {
                        h.merge(n, k)
                    } else {
                        n.push(k)
                    }
                }
                return n
            };
            h.fieldValue = function (j, q) {
                var l = j.name,
                x = j.type,
                y = j.tagName.toLowerCase();
                if (q === undefined) {
                    q = true
                }
                if (q && (!l || j.disabled || x == "reset" || x == "button" || (x == "checkbox" || x == "radio") && !j.checked || (x == "submit" || x == "image") && j.form && j.form.clk != j || y == "select" && j.selectedIndex == -1)) {
                    return null
                }
                if (y == "select") {
                    var r = j.selectedIndex;
                    if (r < 0) {
                        return null
                    }
                    var u = [],
                    k = j.options;
                    var o = (x == "select-one");
                    var s = (o ? r + 1 : k.length);
                    for (var m = (o ? r : 0) ; m < s; m++) {
                        var p = k[m];
                        if (p.selected) {
                            var w = p.value;
                            if (!w) {
                                w = (p.attributes && p.attributes.value && !(p.attributes.value.specified)) ? p.text : p.value
                            }
                            if (o) {
                                return w
                            }
                            u.push(w)
                        }
                    }
                    return u
                }
                return h(j).val()
            };
            h.fn.clearForm = function (i) {
                return this.each(function () {
                    h("input,select,textarea", this).clearFields(i)
                })
            };
            h.fn.clearFields = h.fn.clearInputs = function (i) {
                var j = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;
                return this.each(function () {
                    var l = this.type,
                    k = this.tagName.toLowerCase();
                    if (j.test(l) || k == "textarea") {
                        this.value = ""
                    } else {
                        if (l == "checkbox" || l == "radio") {
                            this.checked = false
                        } else {
                            if (k == "select") {
                                this.selectedIndex = -1
                            } else {
                                if (l == "file") {
                                    if (/MSIE/.test(navigator.userAgent)) {
                                        h(this).replaceWith(h(this).clone(true))
                                    } else {
                                        h(this).val("")
                                    }
                                } else {
                                    if (i) {
                                        if ((i === true && /hidden/.test(l)) || (typeof i == "string" && h(this).is(i))) {
                                            this.value = ""
                                        }
                                    }
                                }
                            }
                        }
                    }
                })
            };
            h.fn.resetForm = function () {
                return this.each(function () {
                    if (typeof this.reset == "function" || (typeof this.reset == "object" && !this.reset.nodeType)) {
                        this.reset()
                    }
                })
            };
            h.fn.enable = function (i) {
                if (i === undefined) {
                    i = true
                }
                return this.each(function () {
                    this.disabled = !i
                })
            };
            h.fn.selected = function (i) {
                if (i === undefined) {
                    i = true
                }
                return this.each(function () {
                    var j = this.type;
                    if (j == "checkbox" || j == "radio") {
                        this.checked = i
                    } else {
                        if (this.tagName.toLowerCase() == "option") {
                            var k = h(this).parent("select");
                            if (i && k[0] && k[0].type == "select-one") {
                                k.find("option").selected(false)
                            }
                            this.selected = i
                        }
                    }
                })
            };
            h.fn.ajaxSubmit.debug = false;
            function f() {
                if (!h.fn.ajaxSubmit.debug) {
                    return
                }
                var i = "[jquery.form] " + Array.prototype.join.call(arguments, "");
                if (window.console && window.console.log) {
                    window.console.log(i)
                } else {
                    if (window.opera && window.opera.postError) {
                        window.opera.postError(i)
                    }
                }
            }
        })((typeof (jQuery) != "undefined") ? jQuery : window.Zepto)
    }
}(jQuery));